/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;
/**
 *
 * @author Chong & Ali
 */
import View.Preferences;

import java.awt.Image;
import java.net.URL;
import javax.swing.ImageIcon;

public class Player extends GameObject {
    
    public static final int PIXEL = Level.PIXEL;
    
    
    public Player(Location p) {
        super(p);
        URL loc = this.getClass().getResource("player.png");
        Image image = new ImageIcon(loc).getImage();
        super.setImage(image);
    }
    
     /**
     * 
     * @param direction The direction that the player is going to.
     * @param locations The matrix of locations the player is currently on.
     */
    public void move(String direction, Location[][] locations){
        // Door de meegegeven richting worden de coordinaten van de buren met behulp van de getNeighbour-methode opgehaald. 
        int x = (this.getLocation().getNeighbour(direction).getXpos())/PIXEL;
        int y = (this.getLocation().getNeighbour(direction).getYpos())/PIXEL;
        
        Location currentLoc = this.getLocation();
        Location neighboarLoc = locations[y][x];
        
        // Als de buur leeg is, beweegt de speler een stap naar de gegeven richting.
        if(neighboarLoc.getGameObject() == null){             
            currentLoc.setGameObject(null);
            neighboarLoc.setGameObject(this);
            this.setLocation(neighboarLoc);
        }
        else if (neighboarLoc.getGameObject() instanceof Box){
            //Typecast de buurObject in een box
            Box box = (Box)neighboarLoc.getGameObject();
            if (Preferences.easyRadio.isSelected()){
                if (box.superMove(direction, locations) == true){
                    currentLoc.setGameObject(null);
                    neighboarLoc.setGameObject(this);
                    this.setLocation(neighboarLoc);
                }
            }
            else {
                if (box.move(direction, locations) == true){
                    currentLoc.setGameObject(null);
                    neighboarLoc.setGameObject(this);
                    this.setLocation(neighboarLoc);
                }
            }
        }
    } 
}
